#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pymysql


class MysqlElephantV2():
	def __init__(self, host="rm-2ze108d8naeso02i1o.mysql.rds.aliyuncs.com", user="elephant", password="K6hd562P1m",
	             database="elephant_v2", charset="utf8", port=3306):
		"""
		MySQL初始化
		:param host:
		:param user:
		:param password:
		:param database:
		:param port:
		"""
		self.host = host
		self.user = user
		self.password = password
		self.database = database
		self.charset = charset
		self.port = port
		self.db = None
		self.curs = None
		
		# 数据库连接
		
		try:
			self.db = pymysql.connect(host=self.host, user=self.user, password=self.password, database=self.database,
			                          charset=self.charset)
			self.curs = self.db.cursor()
			print("elephant_v2 连接成功")
		except pymysql.MySQLError as e:
			print(e.args)
	
	# 数据库关闭
	def close(self):
		self.curs.close()
		self.db.close()
	
	# 数据增删改
	
	def cud(self, sql):
		
		try:
			self.curs.execute(sql)
			self.db.commit()
			print("ok")
		except:
			print('cud出现错误')
			self.db.rollback()
	
	# 数据查询
	def find(self, sql, order):
		"""

		:param order = 1 =》fetchall()  ；其他 =》fetchone()

		 """
		
		try:
			result = self.curs.execute(sql)
			if order == 1:
				results = self.curs.fetchall()
			else:
				results = self.curs.fetchone()
			
			print("ok")
			return results
		except:
			print('find出现错误')


class MysqlCompareV2():
	def __init__(self, host="rm-2ze108d8naeso02i1o.mysql.rds.aliyuncs.com", user="elephant", password="K6hd562P1m",
	             database="compare_v2", charset="utf8", port=3306):
		"""
		MySQL初始化
		:param host:
		:param user:
		:param password:
		:param database:
		:param port:
		"""
		self.host = host
		self.user = user
		self.password = password
		self.database = database
		self.charset = charset
		self.port = port
		self.db = None
		self.curs = None
		
		# 数据库连接
		
		try:
			self.db = pymysql.connect(host=self.host, user=self.user, password=self.password, database=self.database,
			                          charset=self.charset)
			self.curs = self.db.cursor()
			print("compare_v2 连接成功")
		except pymysql.MySQLError as e:
			print(e.args)
	
	# 数据库关闭
	def close(self):
		self.curs.close()
		self.db.close()
	
	# 数据增删改
	
	def cud(self, sql):
		
		try:
			self.curs.execute(sql)
			self.db.commit()
			print("ok")
		except:
			print('cud出现错误')
			self.db.rollback()
	
	# 数据查询
	def find(self, sql, order):
		"""

		:param order = 1 =》fetchall()  ；其他 =》fetchone()

		 """
		
		try:
			result = self.curs.execute(sql)
			if order == 1:
				results = self.curs.fetchall()
			else:
				results = self.curs.fetchone()
			
			print("ok")
			return results
		except:
			print('find出现错误')
		
		# obj = MysqlCompareV2()
		# sql = "SELECT COUNT(*) FROM compare_202488 WHERE task_id = 205478"
		# resu = obj.find(sql,1)
		# print resu


class Mysql_zpt:
	def __init__(self, host="rm-2zezq40w18v8dqcy2.mysql.rds.aliyuncs.com", user="root", password="2bWP*qU8W$%",
	             database="zpt", charset="utf8", port=3306):
		"""
		MySQL初始化
		:param host:
		:param user:
		:param password:
		:param database:
		:param port:
		"""
		self.host = host
		self.user = user
		self.password = password
		self.database = database
		self.charset = charset
		self.port = port
		self.db = None
		self.curs = None
		
		# 数据库连接
		
		try:
			self.db = pymysql.connect(host=self.host, user=self.user, password=self.password, database=self.database,
			                          charset=self.charset)
			self.curs = self.db.cursor()
			print("compare_v2 连接成功")
		except pymysql.MySQLError as e:
			print(e.args)
	
	# 数据库关闭
	def close(self):
		self.curs.close()
		self.db.close()
	
	# 数据增删改
	
	def cud(self, sql):
		
		try:
			self.curs.execute(sql)
			self.db.commit()
			print("ok")
		except:
			print('cud出现错误')
			self.db.rollback()
	
	# 数据查询
	def find(self, sql, order):
		"""

		:param order = 1 =》fetchall()  ；其他 =》fetchone()

		 """
		
		try:
			result = self.curs.execute(sql)
			if order == 1:
				results = self.curs.fetchall()
			else:
				results = self.curs.fetchone()
			
			print("ok")
			return results
		except:
			print('find出现错误')
		
		# obj = MysqlCompareV2()
		# sql = "SELECT COUNT(*) FROM compare_202488 WHERE task_id = 205478"
		# resu = obj.find(sql,1)
		# print resu


class Mysql_loc:
	def __init__(self, host="localhost", user="root", password="wenwen",
	             database="mydb", charset="utf8", port=3306):
		"""
		MySQL初始化
		:param host:
		:param user:
		:param password:
		:param database:
		:param port:
		"""
		self.host = host
		self.user = user
		self.password = password
		self.database = database
		self.charset = charset
		self.port = port
		self.db = None
		self.curs = None
		
		# 数据库连接
		
		try:
			self.db = pymysql.connect(host=self.host, user=self.user, password=self.password, database=self.database,
			                          charset=self.charset)
			self.curs = self.db.cursor()
			print("compare_v2 连接成功")
		except pymysql.MySQLError as e:
			print(e.args)
	
	# 数据库关闭
	def close(self):
		self.curs.close()
		self.db.close()
	
	# 数据增删改
	
	def cud(self, sql):
		
		try:
			self.curs.execute(sql)
			self.db.commit()
			print("ok")
		except:
			print('cud出现错误')
			self.db.rollback()
	
	# 数据查询
	def find(self, sql, order):
		"""

		:param order = 1 =》fetchall()  ；其他 =》fetchone()

		 """
		
		try:
			result = self.curs.execute(sql)
			if order == 1:
				results = self.curs.fetchall()
			else:
				results = self.curs.fetchone()
			
			print("ok")
			return results
		except:
			print('find出现错误')
		
		# obj = MysqlCompareV2()
		# sql = "SELECT COUNT(*) FROM compare_202488 WHERE task_id = 205478"
		# resu = obj.find(sql,1)
		# print resu


class Mysql_56():
	def __init__(self, host="rm-2ze108d8naeso02i1o.mysql.rds.aliyuncs.com", user="elephant", password="K6hd562P1m",
	             database="compare_v2", charset="utf8", port=3306):
		"""
		MySQL初始化
		:param host:
		:param user:
		:param password:
		:param database:
		:param port:
		"""
		self.host = host
		self.user = user
		self.password = password
		self.database = database
		self.charset = charset
		self.port = port
		self.db = None
		self.curs = None
		
		# 数据库连接
		
		try:
			self.db = pymysql.connect(host=self.host, user=self.user, password=self.password, database=self.database,
			                          charset=self.charset)
			self.curs = self.db.cursor()
			print("compare_v2 56 连接成功")
		except pymysql.MySQLError as e:
			print(e.args)
	
	# 数据库关闭
	def close(self):
		self.curs.close()
		self.db.close()
	
	# 数据增删改
	
	def cud(self, sql):
		
		try:
			self.curs.execute(sql)
			self.db.commit()
			print("ok")
		except:
			print('cud出现错误')
			self.db.rollback()
	
	# 数据查询
	def find(self, sql, order):
		"""

		:param order = 1 =》fetchall()  ；其他 =》fetchone()

		 """
		
		try:
			result = self.curs.execute(sql)
			if order == 1:
				results = self.curs.fetchall()
			else:
				results = self.curs.fetchone()
			
			print("ok")
			return results
		except:
			print('find出现错误')

